package com.xingkeduo.business.order.controller;

import com.xingkeduo.business.order.service.CommentsService;
import com.xingkeduo.dto.QueryByAdminIdResponseDto;
import com.xingkeduo.dto.QueryUserCenterResponseDto;
import com.xingkeduo.dto.ScreenCommentDto;
import com.xingkeduo.dto.param.*;
import com.xingkeduo.pojo.table.Comments;
import com.xingkeduo.pojo.table.Labels;
import com.xingkeduo.utils.ResponseReviewUtils;
import com.xingkeduo.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

import static com.xingkeduo.utils.Constant.API_URL_PREFIX;

/**
 * @author chi  2019-02-13 15:10
 **/
@RestController
@RequestMapping(API_URL_PREFIX + "/comments")
@Slf4j
public class CommentsController {

    @Resource
    private CommentsService commentsService;

    /**
     * 发型师展示 查询发型师评论列表
     * @return
     */
    @GetMapping("/query/admin")
    public ResponseEntity getAdmin(@Valid QueryByAdminIdDto queryByAdminIdDto){
        return new ResponseEntity<>(ResponseUtils.getSuccess(commentsService.selectListAdminIdPage(queryByAdminIdDto)), HttpStatus.OK);
    }


    /**
     * 查询评论详情
     * @return
     */
    @GetMapping("/query/{id}")
    public ResponseEntity getCommetById(@PathVariable String id){
        QueryByAdminIdResponseDto commentsResponseDto = commentsService.queryCommetById(id);
        return new ResponseEntity<>(ResponseUtils.getSuccess(commentsResponseDto), HttpStatus.OK);
    }


    /**
     * 店铺端展示 查询评论列表
     * @return
     */
    @GetMapping("/query/store")
    public ResponseEntity getStore(@Valid QueryByStoredDto queryByStoredDto){
        return new ResponseEntity<>(ResponseUtils.getSuccess(commentsService.selectListStoreIdPage(queryByStoredDto)), HttpStatus.OK);
    }


    /**
     * 个人中心-评论列表展示
     * @return
     */
    @GetMapping("/query/user")
    public ResponseEntity getCommensByUserId(@Valid QueryByUserIdDto queryByUserIdDto){
        return new ResponseEntity<>(ResponseUtils.getSuccess(commentsService.selectListUserIdPage(queryByUserIdDto)), HttpStatus.OK);
    }


    /**
     *  个人中心查询评论详情
     * @return
     */
    @GetMapping("/center/{id}")
    public ResponseEntity getCommetCenter(@PathVariable String id){
        QueryUserCenterResponseDto commentsResponseDto = commentsService.queryCommetCenter(id);
        return new ResponseEntity<>(ResponseUtils.getSuccess(commentsResponseDto), HttpStatus.OK);
    }


    /**
     * 新增评论根据订单id
     * @param
     * @return
     */
    @PostMapping("/add")
    public ResponseEntity insert(@RequestBody @Valid CommentInitDto commentInitDto) {
        long id = commentsService.insertComment(commentInitDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(id), HttpStatus.OK);
    }

    /**
     * 新增评论根据订单No
     * @param
     * @return
     */
    @PostMapping("/add/no")
    public ResponseEntity insertNO(@RequestBody @Valid CommentNoInitDto commentNoInitDto) {
        long id = commentsService.insertCommentNo(commentNoInitDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(id), HttpStatus.OK);
    }


    /**
     * 根据id，查询订单的评论
     * @param orderId
     * @return
     */
    @GetMapping("/detail/{orderId}")
    public ResponseEntity queryDetailByorderId(@PathVariable String orderId){
        Comments comments   = commentsService.queryDetailByorderId(orderId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(comments), HttpStatus.OK);
    }


    /**
     * 根据orderNo查询评论信息
     * @param orderNo
     * @return
     */
    @GetMapping("/detail/orderNo")
    public ResponseEntity queryDetailByorderNo(String orderNo){
        Comments comments   = commentsService.queryDetailByorderNo(orderNo);
        return new ResponseEntity<>(ResponseUtils.getSuccess(comments), HttpStatus.OK);
    }


    @GetMapping("/lables/{start}")
    public ResponseEntity queryLabels(@PathVariable int start){
        log.info("queryLabels{}",start);
        List<Labels> labels   = commentsService.queryLabelsByStart(start);
        return new ResponseEntity<>(ResponseUtils.getSuccess(labels), HttpStatus.OK);
    }


    /**
     * 获取好评信息（小程序）
     * @param storeId
     * @return
     */
    @GetMapping("/detail/reviews")
    public ResponseEntity queryReviews(String storeId){
        Integer reviews = commentsService.getReviews(storeId);
        Comments reviewComments = commentsService.getReviewComments(storeId);
        return new ResponseEntity<>(ResponseReviewUtils.getSuccess(reviewComments,reviews), HttpStatus.OK);
    }


    /**
     * 下单屏评论显示
     * @param storeId
     * @return
     */
    @GetMapping("/praise")
    public ResponseEntity praise(String storeId){
        List<ScreenCommentDto> comments = commentsService.praise(storeId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(comments), HttpStatus.OK);
    }


    /**
     * 查询当日差评论
     * @param storeId
     * @return
     */
    @GetMapping("/bad/comments")
    public ResponseEntity bad(String storeId){
        String s = commentsService.querybadComment(storeId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(s), HttpStatus.OK);
    }

    /**
     * 查询门店当日评论与差评数
     * @param storeId
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("/service/{storeId}/{startTime}/{endTime}")
    public ResponseEntity quality(@PathVariable("storeId") String storeId,@PathVariable("startTime") LocalDateTime startTime,@PathVariable("endTime") LocalDateTime endTime){
        return new ResponseEntity<>(ResponseUtils.getSuccess(commentsService.queryServiceQuailty(storeId,startTime,endTime)), HttpStatus.OK);
    }

    /**
     * 统计门店内详情数
     * @param storeId
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("/details/service/{storeId}/{startTime}/{endTime}")
    public ResponseEntity detailsQuality(@PathVariable("storeId") String storeId,@PathVariable("startTime") LocalDateTime startTime,@PathVariable("endTime") LocalDateTime endTime){
        return new ResponseEntity<>(ResponseUtils.getSuccess(commentsService.queryDetailServiceQuality(storeId,startTime,endTime)),HttpStatus.OK);
    }

    /**
     * 发型师评价与差评数统计
     * @param storeId
     * @param adminId
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("/adminId/service/{storeId}/{adminId}/{startTime}/{endTime}")
    public ResponseEntity serviceAdminId(@PathVariable("storeId") String storeId,@PathVariable("adminId")String adminId,@PathVariable("startTime") LocalDateTime startTime,@PathVariable("endTime") LocalDateTime endTime){
        return new ResponseEntity<>(ResponseUtils.getSuccess(commentsService.serviceAdminId(storeId,adminId,startTime,endTime)),HttpStatus.OK);
    }


    /**
     * 评论成功修改订单(用户端)
     *
     * @return
     */
    @PutMapping("/aftermarket")
    public ResponseEntity aftermarket(String orderNo) {
        commentsService.edithadComment(orderNo);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }

    /**
     * 服务发型师name
     * @author: lyz
     * @return
     */
    @GetMapping("/serviceAdmin")
    public ResponseEntity serviceAdmin(String storeId){
        List<Map<String, Object>> maps = commentsService.serviceAdmin(storeId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(maps),HttpStatus.OK);
    }

    /**
     * 门店name
     * @param adminId
     * @author: lyz
     * @return
     */
    @GetMapping("/serviceStore")
    public ResponseEntity serviceStore(String adminId){
        List<Map<String, Object>> maps = commentsService.serviceStore(adminId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(maps),HttpStatus.OK);
    }
}
























